package com.sinoma.G2project.MoYu.app;


import com.alibaba.fastjson.JSON;
import com.firenay.common.constant.AuthServerConstant;
import com.sinoma.G2project.MoYu.Service.DataSelectService;
import com.sinoma.G2project.MoYu.vo.MoYuVo;
import com.sinoma.G2project.utils.jsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpSession;
import java.util.HashMap;

@Slf4j
@Controller
@RequestMapping("/MoYu")
public class IndexController {

    @Autowired
    private DataSelectService dataSelectService;

    @GetMapping("/MoYuShow")
    public String showMoYu(Model model, HttpSession session){
        if (session.getAttribute(AuthServerConstant.LOGIN_USER) ==null) {
            return "redirect:http://g2p.com/login.html";
        }

        MoYuVo vo = dataSelectService.getLatest();
        dataSelectService.checkUser(vo,session.getAttribute(AuthServerConstant.LOGIN_USER));
        jsonUtils utils = new jsonUtils();
        String s = utils.getjson();
        Object parse = JSON.parse(s);
        HashMap<Object, Object> map = new HashMap<>();
        model.addAttribute("dict",parse);
        model.addAttribute("item",vo);
        return "moYuShow";

    }

    @GetMapping("/index")
    public String showIndex(Model model, HttpSession session){
        if (session.getAttribute(AuthServerConstant.LOGIN_USER) ==null) {
            return "redirect:http://G2P.com/login.html";
        }
        MoYuVo vo = dataSelectService.getLatest();
        model.addAttribute("item",vo);
        return "index";

    }


}
